import AssetLoaderComponent from "@runtime/UnityEngineBridge/AssetLoaderComponent";
import GameObjectComponent from "@runtime/UnityEngineBridge/GameObjectComponent";

/**
 * 房间组件
 */
export default class RoomComponent {
    private static instance: RoomComponent = new RoomComponent();
    /**
     * 房间组件
     */
    public static get Default(): RoomComponent {
        return this.instance;
    }

    constructor() {
        window.addEventListener('unload', this.Dispose.bind(this));
    }

    Dispose() {
        window.removeEventListener('unload', this.Dispose);
    }

    private instanceId: number = 0;

    private async LoadAsync(): Promise<void> {
        this.instanceId = await AssetLoaderComponent.Default.LoadAsync('Assets/R00034/ICV/Product/Room/Product/Room.prefab');
    }

    public async ShowAsync(): Promise<void> {
        if (this.instanceId == 0) {
            await this.LoadAsync();
        } else {
            await GameObjectComponent.Default.ShowAsync(this.instanceId);
        }
    }

    public async HideAsync(): Promise<void> {
        if (this.instanceId == 0) {
            return;
        }

        await GameObjectComponent.Default.HideAsync(this.instanceId);
    }
}